﻿//Order.aspx.cs
////////////////////////////////////////
////////////////////////////////////////
//当点击首页的“我的订单”时显示，显示用户的所有订单
////////////////////////////////////////
////////////////////////////////////////
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

public partial class User_Order : System.Web.UI.Page
{
    DataTable dtOrder;
    CommonClass ccObj = new CommonClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        //判断Session["User"]有没订单。如果存在则取出，并调用自定义方法将列表绑定到GridViewk中。
        Client user = (Client)Session["User"];
        Order order = new Order();
        this.dtOrder = order.GetOrdersByUser(user.clientID);
        if (dtOrder.Rows.Count > 0)
        {
            BindMyOrder(this.dtOrder);
        }
        else
        {
            Response.Write(ccObj.MessageBox("您的订单为空！", "Default.aspx"));
            this.MyOrderView.Visible = false;
            this.btnOK.Visible = false;
        }
    }
    private void BindMyOrder(DataTable dtOrder)
    {
        this.MyOrderView.DataSource = dtOrder;
        this.MyOrderView.DataBind();
    }
    protected void lnkbtnCheck_Command(object sender, CommandEventArgs e)
    {
        //查看指定的订单，其中，查看按钮(lnkbtnCheck)的CommandArgument参数值为订单ID代号
        Response.Redirect("OrderList.aspx?orderID=" + e.CommandArgument);
    }
    protected void MyOrderView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        MyOrderView.PageIndex = e.NewPageIndex;
        this.BindMyOrder(this.dtOrder);
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}
